package com.barneyx.mshinfoplatform.web.front.info;

import com.barneyx.mshinfoplatform.common.ExResult;
import com.barneyx.mshinfoplatform.exception.MshException;
import com.barneyx.mshinfoplatform.util.InfoUtil;
import org.springframework.cache.annotation.CachePut;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/front/info/settings/")
public class InfoSettingController {

    @Resource
    private InfoUtil.Setting infoSettingUtil;


    /**
     * 获取当前用户的所在区域的广告列表
     *
     * @return
     * @throws MshException
     */
    @GetMapping("/current-user-area-adv-list")
    public ExResult getAdvList() throws MshException {
        return ExResult.ofAuto(infoSettingUtil.getAdvList());
    }

    @GetMapping("/current-user-area-setting")
    @CachePut(cacheNames = "INFO_SETTING",key="#code")
    public ExResult<?> getCurrentUserAreaSettingByKey(@RequestParam("code") String code) throws MshException {
        return ExResult.ofAuto(infoSettingUtil.getInfoSetting(code));
    }
    @GetMapping("/info-setting-by-code")
    @CachePut(cacheNames = "INFO_SETTING",key="#code")
    public ExResult<?> getInfoSettingByCode(@RequestParam("code") String code) throws MshException {
        return ExResult.ofAuto(infoSettingUtil.getInfoSettingNoArea(code));
    }

}
